﻿#region using statements

using AeonOfStrife.Objects.Castle;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using NGen;
using NGen.Managers.GameObject.Fsm;
using NGen.Systems.Graphics;

#endregion

namespace AeonOfStrife.Objects.Units.UnitStates
{
	public abstract class UnitState : GameObject2DFsmState<Unit>
	{
		public AnimatedSprite AnimatedSprite { get; protected set; }

		internal UnitState(AnimationInfo p_animationInfo) {
			var spriteSheet = GameEngine.GameContent.Load<Texture2D>(p_animationInfo.m_spritesheet);
			AnimatedSprite =
				new AnimatedSprite(
					spriteSheet,
					p_animationInfo.m_frameSize,
					p_animationInfo.m_spritesheetDimensions,
					UnitConstants.c_FRAME_DELAY);
		}

		public override void Draw(GameTime p_gameTime) {
			AnimatedSprite.Update(p_gameTime);
			GameEngine.SpriteBatch.Draw(
				AnimatedSprite.AnimationSpriteSheet,
				Parent.m_position,
				AnimatedSprite.GetFrame(),
				Parent.m_textureTint,
				0,
				AnimatedSprite.Origin,
				Parent.m_scale,
				Parent.m_spriteEffects,
				Parent.m_zDepth);
		}

		public override void Initialize() {
		}

		public override void Update(GameTime p_gameTime) {
			AnimatedSprite.Update(p_gameTime);
		}

		public override void Cleanup() {}

		public override void OnExit() {}

		public override void OnEnter() {
			AnimatedSprite.ResetAnimation();
		}
	}
}